// utils/timeFormat.js

export function formatAccountAge(registerTime) {
	const now = new Date();
	const regTime = new Date(registerTime);

	let years = now.getFullYear() - regTime.getFullYear();
	let months = now.getMonth() - regTime.getMonth();

	// 如果本月还没到注册日期，则减一个月
	if (now.getDate() < regTime.getDate()) {
		months--;
	}

	// 总月数
	const totalMonths = years * 12 + months;

	if (totalMonths <= 0) {
		return '几个月';
	}

	const year = Math.floor(totalMonths / 12);
	const month = totalMonths % 12;

	if (year > 0 && month > 0) {
		return `${year}年${month}个月`;
	} else if (year > 0) {
		return `${year}年`;
	} else {
		return `${month}个月`;
	}
}